<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>键盘事件</title>
</head>
<body>
<div id="app">
    <form action="#">
        <!--<label for="username">用户名</label><input type="text" name="username" id="username" v-on:keyup="keyup">-->
        <!--<label for="username">用户名</label><input type="text" name="username" id="username" v-on:keydown="keydown">-->
        <label for="username">用户名</label><input type="text" name="username" id="username" v-on:keypress="keypress">
    </form>
</div>

<script type="module">
    import {createApp} from "../../../js/vue.esm-browser.js";

    let app = createApp(
        {
            setup() {

                function keyup(event) {
                    console.log(event);
                    // 注意：不能在 函数中访问 元素
                    let element = document.querySelector("#username");
                    console.log(element.value);
                }

                function keydown(event) {
                    console.log(event);
                    // 注意：不能在 函数中访问 元素
                    let element = document.querySelector("#username");
                    console.log(element.value);
                }

                function keypress(event) {
                    console.log(event);
                    // 注意：不能在 函数中访问 元素
                    let element = document.querySelector("#username");
                    console.log(element.value);
                }

                return {
                    keyup,
                    keydown,
                    keypress,
                }
            }
        }
    );

    app.mount("#app")
</script>
</body>
</html>